// 新增分类表单
import { Form, Select, Input } from 'antd';

// const Item = Form.Item;
// const Option = Select.Option;
const AddForm = ({ categorys, parentId, setForm, setSelectedCategory }) => {
    const [form] = Form.useForm();
    // 选中项改变时的回调函数
    const handleSelectChange = (value, option) => {
        setSelectedCategory(option);
    };

    return (
        <Form form={form}>
            <Form.Item
                name="parentId"
                initialValue={parentId}
            >
                <Select onChange={handleSelectChange}>
                    <Select.Option value="0">一级分类</Select.Option>
                    {categorys.map((c) => (
                        <Select.Option value={c._id} key={c._id}>
                            {c.name}
                        </Select.Option>
                    ))}
                </Select>
            </Form.Item>

            <Form.Item
                name="categoryName"
                rules={[{ required: true, message: '分类名称必须输入' }]}
                initialValue={''}
            >
                <Input placeholder="请输入分类名称" onChange={(e) => setForm(e.target.value)} />
            </Form.Item>
        </Form>
    );
};

export default AddForm;
